package com.igeekhome.ccs.controller;


import com.igeekhome.ccs.biz.ICustomerBiz;
import com.igeekhome.ccs.biz.ICustomerServiceBiz;
import com.igeekhome.ccs.biz.IJobBiz;
import com.igeekhome.ccs.entity.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

//客户详情页面
@Controller
@RequestMapping("/customerDetail")
public class CustomerDetailcontroller {
    @Autowired
    ICustomerBiz iCustomerbiz;
    @Autowired
    IJobBiz iJobBiz;
    @Autowired
    ICustomerServiceBiz iCustomerServiceBiz;
    /**
     * 这里是客户详情页面
     */
    @RequestMapping("/select")
    public @ResponseBody
    List<Customer> select(@RequestBody Map<String,String> map){
        Customer cs=new Customer();
        CustomerService cs1 = iCustomerServiceBiz.getOneByUsername((String) SecurityUtils.getSubject().getPrincipal());
        cs.setCsId(cs1.getCsId());
        cs.setCustomerId(Integer.parseInt(map.get("customerId")));
        return iCustomerbiz.select(cs);
    }
    /**
     * 会话查询页面
     */
    @RequestMapping("selectsession")
    public @ResponseBody
    List<Session> selectsession(@RequestBody Map<String,String> map){

        return iCustomerbiz.selectsession(Integer.parseInt(map.get("customerId")));
    }
    /**
     * 历史工单
     */
    @RequestMapping("selectjob")
    public @ResponseBody
    List<Job> selectjob(@RequestBody Map<String,String> map){
        Job jb=new Job();
        jb.setCustomerId(Integer.parseInt(map.get("customerId")));
        return iJobBiz.select(jb);
    }
    /**
     * 拉黑记录
     */
    @RequestMapping("selectHater")
    public @ResponseBody
    List<Hater> selecthater(@RequestBody Map<String,String> map){
        return iCustomerbiz.selecthater(Integer.parseInt(map.get("customerId")));
    }
    /**
     * 编辑客户信息
     */
    @RequestMapping("updatecustomer")
    public @ResponseBody
    String updatecustomer(@RequestBody Map<String,String> map){
        Customer cs=new Customer();
        cs.setCustomerId(Integer.parseInt(map.get("customerId")));
        cs.setCustomerName(map.get("customerName"));
        cs.setRealName(map.get("realName"));
        cs.setPhone(map.get("phone"));
        cs.setEmail(map.get("email"));
        cs.setCompany(map.get("company"));
        cs.setAddress(map.get("address"));
        cs.setGrade(map.get("grade"));
        cs.setSourceWay(map.get("sourceWay"));
        cs.setLabelId(Integer.parseInt(map.get("labelId")));
        cs.setRemark(map.get("remark"));
        Date date=new Date();
        cs.setUpdataTime(date);
        iCustomerbiz.updatecustomer(cs);
        return null;
    }
}
